// pages/education_experience/education_experience.js
const app = getApp(), core = require('../../utils/core'), util = require('../../utils/util'), WeValidator = require('../../utils/we-validator');
WeValidator.addRule('gt',{
  rule: function (value, fieldName) {
    console.log(this);
    return value > this.data[fieldName];
  },
});
Page({

  /**
   * 页面的初始数据
   */
  data: {
    textNum:0
  },


  textCount:function(e){
    this.setData({
      textNum:e.detail.value.length
    })
  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getOpenerEventChannel().on('dataTransfer', data => {
      this.setData({
        model: Object.assign({},data.model), //创建一份浅拷贝, 不影响上一页的值
      });
      this.setData({
        textNum:this.data.model.content.length
      })
    });
  },

  bindSubmit(event) {
    let data = event.detail.value;
    let validator = new WeValidator({
      rules: {
        'content': {required:true}
      },
      messages: {
        'content': {required:'请填写内容'}
      }
    });
    if(!validator.checkData(data)) {
      return;
    }
    data.module = 'summary';
    core.post({
      url: 'xilujob.user/save_module',
      data: data,
      success: ret => {
        this.getOpenerEventChannel().emit('dataTransfer', {model: ret.data.model, complete_percent:ret.data.complete_percent});
        wx.navigateBack();
      }
    });
  },

});
